package com.liuyjy.base.cloud.config;

import feign.Feign;
import feign.form.spring.SpringFormEncoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope;

/**
 * @Author liuyjy
 * @Date 2024/12/14 19:00
 * @Description: FeignConfig
 **/
@Configuration
public class FeignConfig {

    @Autowired
    private ObjectFactory<HttpMessageConverters> messageConverters;

    /**
     * 解决feign上传文件乱码问题
     *
     * @return SpringFormEncoder
     */
    @Bean
    public SpringFormEncoder feignFormEncoder() {
        return new SpringFormEncoder(new SpringEncoder(messageConverters));
    }

    @Primary
    @Bean
    @Scope("prototype")
    public Feign.Builder feignBuilder() {
        return Feign.builder();
    }
//    @Bean
//    public Request.Options feignOptions() {
//        // 连接超时和读取超时时间
//        return new Request.Options(1000, 1000);
//    }
//
//    @Bean
//    public IRule randomRule() {
//        // 使用随机策略
//        return new AvailabilityFilteringRule();
//    }
}
